clear
set more off
cap log cl


local y `1'

// 2000 raw CBP

insheet using "${raw}/cbp/cbp`y'co.txt", comma names clear
cd $temp


// Start of Autor-Dorn code

* drop unused payroll variables
drop ap


*******************************************************************
* Adjust to variable name convention of CBP 1980
*******************************************************************

rename fipscty fipscty2
rename empflag flag
rename emp tempmm
rename est testab
rename n1_4 ctyemp1
rename n5_9 ctyemp2
rename n10_19 ctyemp3
rename n20_49 ctyemp4
rename n50_99 ctyemp5
rename n100_249 ctyemp6
rename n250_499 ctyemp7
rename n500_999 ctyemp8
rename n1000 ctyemp9
rename n1000_1 ctyemp10
rename n1000_2 ctyemp11
rename n1000_3 ctyemp12
rename n1000_4 ctyemp13
rename censtate  state2
rename cencty  county2

*******************************************************************
* Geographic selection
*******************************************************************

* drop Alaska and Hawaii
*****drop if fipstate==2 | fipstate==15


destring naics, force replace
drop if naics == .

gen countyid=fipstate*1000+fipscty2


keep countyid naics testab ctye*  flag state2


if (`y' <= 20) gen year = 2000 + `y'
if (`y' >  20) gen year = 1900 + `y'
sum year
local h =r(mean)
 
save ${wd}/cbp/CPB_`h'_estab.dta, replace 
